package com.ethink.platform.controller.warehouse;

import com.ethink.warehouse.api.request.SubWarehouseStatusSetRequest;
import com.ethink.warehouse.api.response.SubWarehouseAddResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import com.ethink.framework.common.web.BaseController;
import com.ethink.framework.common.web.response.CommonResponse;
import com.ethink.warehouse.api.SubWarehouseFacade;
import com.ethink.warehouse.api.info.SubWarehouseInfo;
import com.ethink.warehouse.api.request.SubWarehouseAddRequest;
import com.ethink.warehouse.api.request.SubWarehouseQueryRequest;
import com.ethink.warehouse.api.request.SubWarehouseUpdateRequest;

/**
 * 仓库分仓 Controller
 *
 * @author default
 * @date 2022-11-01
 */
@Tag(name = "SubWarehouseController", description = "仓库分仓 Controller")
@RestController
@Slf4j
@RequestMapping("platform-server/v1/warehouse-service")
public class SubWarehouseController extends BaseController {

    @Autowired
    private SubWarehouseFacade subWarehouseFacade;

    @Operation(summary = "分页查询")
    @GetMapping("/subWarehouse/query")
    public CommonResponse<List<SubWarehouseInfo>> querySubWarehouse(SubWarehouseQueryRequest request) {
        return succeedWithPage(subWarehouseFacade.querySubWarehouse(request));
    }

    @Operation(summary = "详情查询")
    @GetMapping("/subWarehouse/get/{subWarehouseId}")
    public CommonResponse<SubWarehouseInfo> getSubWarehouseById(@PathVariable("subWarehouseId") Long subWarehouseId) {
        return succeedWith(subWarehouseFacade.getSubWarehouseById(subWarehouseId));
    }

    @Operation(summary = "查询所有")
    @GetMapping("/subWarehouse/list")
    public CommonResponse<List<SubWarehouseInfo>> listSubWarehouse() {
        return succeedWith(subWarehouseFacade.listSubWarehouse());
    }

    @Operation(summary = "新增")
    @PostMapping("/subWarehouse/add")
    public CommonResponse<SubWarehouseAddResponse> addSubWarehouse(@Validated @RequestBody SubWarehouseAddRequest request) {
        return succeedWith(subWarehouseFacade.addSubWarehouse(request));
    }

    @Operation(summary = "更新")
    @PutMapping("/subWarehouse/update")
    public CommonResponse updateSubWarehouse(@Validated @RequestBody SubWarehouseUpdateRequest request) {
        subWarehouseFacade.updateSubWarehouse(request);
        return succeed();
    }

    @Operation(summary = "修改状态")
    @PutMapping("/subWarehouse/setStatus")
    public CommonResponse setSubWarehouseStatus(@Validated @RequestBody SubWarehouseStatusSetRequest request) {
        subWarehouseFacade.setSubWarehouseStatus(request);
        return succeed();
    }

}